home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / thesrc10.zip / COMMSOS.C < prev    next >
C/C++ Source or Header  |  1992-08-12  |  33KB  |  1,045 lines

  1. /***********************************************************************/
  2. /* COMMSOS.C - sos commands.                                           */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991,1992 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@itc.gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 7877
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42.  
  43. #include "the.h"
  44.  
  45. /*#define DEBUG 1*/
  46.  
  47. /*-------------------------- external data ----------------------------*/
  48. extern LINE *first_command,*current_command,*last_command;
  49. extern LINE *next_line,*curr_line;
  50. extern VIEW_DETAILS *vd_current,*vd_first;
  51. extern char current_screen;
  52. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  53. extern char current_file;         /* pointer to current file */
  54. extern WINDOW *foot,*error_window;
  55. extern char error_on_screen;
  56. extern unsigned char *rec;
  57. extern unsigned short rec_len;
  58. extern unsigned char *cmd_rec;
  59. extern unsigned short cmd_rec_len;
  60. extern unsigned char mode_insert;        /* defines insert mode toggle */
  61. extern unsigned char in_profile;    /* indicates if processing profile */
  62. extern unsigned char *tempfilename;
  63. extern unsigned short file_start;
  64.  
  65. extern unsigned char temp_cmd[150];
  66. extern unsigned char dir_filename[80];
  67. extern unsigned char dir_pathname[80];
  68. extern unsigned char sp_path[MAX_FILE_NAME+1] ;
  69. extern unsigned char sp_fname[MAX_FILE_NAME+1] ;
  70. extern unsigned char dir_path[MAX_FILE_NAME+1] ;    /* for dir and ls commands */
  71. /*---------------------- function definitions -------------------------*/
  72. #ifdef PROTO
  73. void split_command(unsigned char *,unsigned char *,unsigned char *);
  74. int param_split(unsigned char *,unsigned char *[],int );
  75. long valid_target(unsigned char *);
  76. int get_row_for_focus_line(int,long,long);
  77. unsigned char *get_key_definition(unsigned short key);
  78. void print_line(char,long,short,unsigned char *,unsigned char *);
  79. bool valid_set_command(char *);
  80. #else
  81. void split_command();
  82. int param_split();
  83. long valid_target();
  84. int get_row_for_focus_line();
  85. unsigned char *get_key_definition();
  86. void print_line();
  87. bool valid_set_command();
  88. #endif
  89. /*man-start*********************************************************************
  90. COMMAND
  91.      sos_addline - add blank line after focus line
  92.  
  93. SYNTAX
  94.      ** effective only if bound to a key **
  95.  
  96. DESCRIPTION
  97.      The sos_addline command inserts a blank line in the file following
  98.      the focus line. The cursor is placed in the column under the first
  99.      non-blank in the focus line.
  100.  
  101. COMPATIBILITY
  102.      Reasonable.
  103.  
  104. SEE ALSO
  105.      sos_delline
  106.  
  107. STATUS
  108.      Complete
  109. **man-end**********************************************************************/
  110. #ifdef PROTO
  111. int Sos_addline(unsigned char *params)
  112. #else
  113. int Sos_addline(params)
  114. unsigned char *params;
  115. #endif
  116. /***********************************************************************/
  117. {
  118. /*--------------------------- local data ------------------------------*/
  119.  short rc;
  120. /*--------------------------- processing ------------------------------*/
  121. #ifdef TRACE
  122.  trace_function("commsos.c: Sos_addline");
  123. #endif
  124.  rc = Add("1");
  125. #ifdef TRACE
  126.  trace_return();
  127. #endif
  128.  return(rc);
  129. }
  130. /*man-start*********************************************************************
  131. COMMAND
  132.      sos_delback - delete the character to the left of the cursor
  133.  
  134. SYNTAX
  135.      ** effective only if bound to a key **
  136.  
  137. DESCRIPTION
  138.      The sos_delback command moves the cursor one character to the left
  139.      and deletes the character now under the cursor.
  140.  
  141. COMPATIBILITY
  142.      Compatible.
  143.  
  144. SEE ALSO
  145.      sos_delchar
  146.  
  147. STATUS
  148.      Complete
  149. **man-end**********************************************************************/
  150. #ifdef PROTO
  151. int Sos_delback(unsigned char *params)
  152. #else
  153. int Sos_delback(params)
  154. unsigned char *params;
  155. #endif
  156. /***********************************************************************/
  157. {
  158. /*--------------------------- local data ------------------------------*/
  159.  unsigned short x,y;
  160. /*--------------------------- processing ------------------------------*/
  161. #ifdef TRACE
  162.  trace_function("commsos.c: Sos_delback");
  163. #endif
  164.  getyx(CURRENT_WINDOW,y,x);
  165.  switch (CURRENT_VIEW->current_window)
  166.    {
  167.     case WINDOW_MAIN:
  168.          if ((CURRENT_VIEW->focus_line == CURRENT_FILE->number_lines+1L
  169.          || CURRENT_VIEW->focus_line== 0L))
  170.            {
  171.             display_error(38,"");
  172. #ifdef TRACE
  173.             trace_return();
  174. #endif
  175.             return(OK);
  176.            }
  177.          break;
  178.     case WINDOW_COMMAND:
  179.          if (x == 0)
  180.             return(OK);
  181.          mvwdelch(CURRENT_WINDOW,y,x-1);
  182.          cmd_rec = (unsigned char *)memdelchr((char *)cmd_rec,
  183.                                                x-1,cmd_rec_len,1);
  184.          cmd_rec_len--;
  185. #ifdef TRACE
  186.          trace_return();
  187. #endif
  188.          return(OK);
  189.          break;
  190.     case WINDOW_PREFIX:
  191.          if (x == 0)
  192.             return(OK);
  193.          mvwdelch(CURRENT_WINDOW,y,x-1);
  194. #ifdef TRACE
  195.          trace_return();
  196. #endif
  197.          return(OK);
  198.          break;
  199.     default:
  200.          break;
  201.    }
  202. /*---------------------------------------------------------------------*/
  203. /* Remainder of processing is only for WINDOW_MAIN.                    */
  204. /*---------------------------------------------------------------------*/
  205.  if (x == 0 && CURRENT_VIEW->verify_start == CURRENT_VIEW->verify_col)
  206.    {
  207. #ifdef TRACE
  208.     trace_return();
  209. #endif
  210.     return(OK);
  211.    }
  212.  Left_arrow("");
  213. /*---------------------------------------------------------------------*/
  214. /* If we are after the last character of the line, exit.               */
  215. /*---------------------------------------------------------------------*/
  216.  if (x+CURRENT_VIEW->verify_col-1 > rec_len)
  217.    {
  218. #ifdef TRACE
  219.     trace_return();
  220. #endif
  221.     return(OK);
  222.    }
  223.  
  224.  getyx(CURRENT_WINDOW,y,x);
  225.  mvwdelch(CURRENT_WINDOW,y,x);
  226.  
  227.  rec = (unsigned char *)memdelchr((char *)rec,CURRENT_VIEW->verify_col-1+x,rec_len,1);
  228.  rec_len--;
  229. /*---------------------------------------------------------------------*/
  230. /* If there is a character off the right edge of the screen, display it*/
  231. /* in the last character of the main window.                           */
  232. /*---------------------------------------------------------------------*/
  233.  if (CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1 < rec_len)
  234.    {
  235.     wmove(CURRENT_WINDOW,y,CURRENT_SCREEN.cols-1);
  236.     put_char(CURRENT_WINDOW,
  237.              rec[CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1],ADDCHAR);
  238.     wmove(CURRENT_WINDOW,y,x);
  239.    }
  240. #ifdef TRACE
  241.  trace_return();
  242. #endif
  243.  return(OK);
  244. }
  245. /*man-start*********************************************************************
  246. COMMAND
  247.      sos_delchar - delete character under cursor
  248.  
  249. SYNTAX
  250.      ** effective only if bound to a key **
  251.  
  252. DESCRIPTION
  253.      The sos_delchar command deletes the character under the cursor.
  254.      Text to the right is shifted to the left.
  255.  
  256. COMPATIBILITY
  257.      Complete
  258.  
  259. STATUS
  260.      Complete
  261. **man-end**********************************************************************/
  262. #ifdef PROTO
  263. int Sos_delchar(unsigned char *params)
  264. #else
  265. int Sos_delchar(params)
  266. unsigned char *params;
  267. #endif
  268. /***********************************************************************/
  269. {
  270. /*--------------------------- local data ------------------------------*/
  271.  unsigned short x,y;
  272. /*--------------------------- processing ------------------------------*/
  273. #ifdef TRACE
  274.  trace_function("commsos.c: Sos_delchar");
  275. #endif
  276. /*---------------------------------------------------------------------*/
  277. /* Do not allow this command on the top or bottom of file lines.       */
  278. /*---------------------------------------------------------------------*/
  279.  if (CURRENT_VIEW->current_window == WINDOW_MAIN
  280.  && ((CURRENT_VIEW->focus_line == CURRENT_FILE->number_lines+1L
  281.      || CURRENT_VIEW->focus_line== 0L)))
  282.       {
  283.        display_error(38,"");
  284. #ifdef TRACE
  285.        trace_return();
  286. #endif
  287.        return(OK);
  288.       }
  289.  getyx(CURRENT_WINDOW,y,x);
  290.  wdelch(CURRENT_WINDOW);
  291.  switch (CURRENT_VIEW->current_window)
  292.    {
  293.     case WINDOW_COMMAND:
  294.          if (x < cmd_rec_len)
  295.            {
  296.             cmd_rec = (unsigned char *)memdelchr((char *)cmd_rec,
  297.                                                x,cmd_rec_len,1);
  298.             cmd_rec_len--;
  299.            }
  300. #ifdef TRACE
  301.          trace_return();
  302. #endif
  303.          return(OK);
  304.          break;
  305.     case WINDOW_PREFIX:
  306. #ifdef TRACE
  307.          trace_return();
  308. #endif
  309.          return(OK);
  310.          break;
  311.     default:
  312.          break;
  313.    }
  314.  
  315. /*---------------------------------------------------------------------*/
  316. /* If we are after the last character of the line, exit.               */
  317. /*---------------------------------------------------------------------*/
  318.  if (x+CURRENT_VIEW->verify_col-1 > rec_len)
  319.    {
  320. #ifdef TRACE
  321.     trace_return();
  322. #endif
  323.     return(OK);
  324.    }
  325.  
  326.  rec = (unsigned char *)memdelchr((char *)rec,CURRENT_VIEW->verify_col-1+x,rec_len,1);
  327.  rec_len--;
  328. /*---------------------------------------------------------------------*/
  329. /* If there is a character off the right edge of the screen, display it*/
  330. /* in the last character of the main window.                           */
  331. /*---------------------------------------------------------------------*/
  332.  if (CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1 < rec_len)
  333.    {
  334.     wmove(CURRENT_WINDOW,y,CURRENT_SCREEN.cols-1);
  335.     put_char(CURRENT_WINDOW,
  336.              rec[CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1],ADDCHAR);
  337.     wmove(CURRENT_WINDOW,y,x);
  338.    }
  339. #ifdef TRACE
  340.  trace_return();
  341. #endif
  342.  return(OK);
  343. }
  344. /*man-start*********************************************************************
  345. COMMAND
  346.      sos_delend - delete to end of line
  347.  
  348. SYNTAX
  349.      ** effective only if bound to a key **
  350.  
  351. DESCRIPTION
  352.      The sos_delend command deletes all characters from the current
  353.      column to the end of line.
  354.  
  355. COMPATIBILITY
  356.      Complete
  357.  
  358. STATUS
  359.      Complete.
  360. **man-end**********************************************************************/
  361. #ifdef PROTO
  362. int Sos_delend(unsigned char *params)
  363. #else
  364. int Sos_delend(params)
  365. unsigned char *params;
  366. #endif
  367. /***********************************************************************/
  368. {
  369. /*--------------------------- local data ------------------------------*/
  370.  register short i;
  371.  unsigned short col,x,y;
  372. /*--------------------------- processing ------------------------------*/
  373. #ifdef TRACE
  374.  trace_function("commsos.c: Sos_delend");
  375. #endif
  376.  getyx(CURRENT_WINDOW,y,x);
  377.  switch (CURRENT_VIEW->current_window)
  378.    {
  379.     case WINDOW_MAIN:
  380.          if (CURRENT_VIEW->focus_line == CURRENT_FILE->number_lines+1L
  381.          || CURRENT_VIEW->focus_line== 0L)
  382.            {
  383.             display_error(38,"");
  384. #ifdef TRACE
  385.             trace_return();
  386. #endif
  387.             return(OK);
  388.            }
  389.          col = x + CURRENT_VIEW->verify_col - 1;
  390.          for (i=col;i<MAX_LINE_LENGTH;i++)
  391.              rec[i] = ' ';
  392.          if (rec_len > col)
  393.             rec_len = col;
  394.          break;
  395.     case WINDOW_COMMAND:
  396.          for (i=x;i<COLS;i++)
  397.              cmd_rec[i] = ' ';
  398.          if (cmd_rec_len > x)
  399.             cmd_rec_len = x;
  400.          break;
  401.     case WINDOW_PREFIX:
  402.          break;
  403.     default:
  404.          break;
  405.    }
  406.  wclrtoeol(CURRENT_WINDOW);
  407. #ifdef TRACE
  408.  trace_return();
  409. #endif
  410.  return(OK);
  411. }
  412. /*man-start*********************************************************************
  413. COMMAND
  414.      sos_delline - delete focus line
  415.  
  416. SYNTAX
  417.      ** effective only if bound to a key **
  418.  
  419. DESCRIPTION
  420.      The sos_delline command deletes the focus line.
  421.  
  422. COMPATIBILITY
  423.      Complete
  424.  
  425. STATUS
  426.      Complete
  427. **man-end**********************************************************************/
  428. #ifdef PROTO
  429. int Sos_delline(unsigned char *params)
  430. #else
  431. int Sos_delline(params)
  432. unsigned char *params;
  433. #endif
  434. /***********************************************************************/
  435. {
  436. /*--------------------------- local data ------------------------------*/
  437.  short rc;
  438. /*--------------------------- processing ------------------------------*/
  439. #ifdef TRACE
  440.  trace_function("commsos.c: Sos_delline");
  441. #endif
  442.  rc = Delete_line("1");
  443. #ifdef TRACE
  444.  trace_return();
  445. #endif
  446.  return(rc);
  447. }
  448. /*man-start*********************************************************************
  449. COMMAND
  450.      sos_edit - edit a file from directory list
  451.  
  452. SYNTAX
  453.      ** effective only if bound to a key **
  454.  
  455. DESCRIPTION
  456.      The sos_edit command allows the user to edit a file, chosen from
  457.      a directory list.(the file DIR.DIR).
  458.  
  459. COMPATIBILITY
  460.      Compatible.
  461.  
  462. STATUS
  463.      Complete.
  464. **man-end**********************************************************************/
  465. #ifdef PROTO
  466. int Sos_edit(unsigned char *params)
  467. #else
  468. int Sos_edit(params)
  469. unsigned char *params;
  470. #endif
  471. /***********************************************************************/
  472. {
  473. /*--------------------------- local data ------------------------------*/
  474.  register short i,j;
  475.  unsigned short col,x,y;
  476.  LINE *curr;
  477.  unsigned char edit_fname[MAX_FILE_NAME];
  478.  short rc;
  479. /*--------------------------- processing ------------------------------*/
  480. #ifdef TRACE
  481.  trace_function("commsos.c: Sos_edit");
  482. #endif
  483. /*---------------------------------------------------------------------*/
  484. /* This command is only valid from within the special DIR.DIR file;    */
  485. /* not from the command line and not on the top or bottom lines.       */
  486. /* Ignore the command if attempted execution from the above.           */
  487. /*---------------------------------------------------------------------*/
  488.  if (strcmp(CURRENT_FILE->fname,dir_filename) != 0
  489.  ||  CURRENT_VIEW->current_window == WINDOW_COMMAND)
  490.    {
  491. #ifdef TRACE
  492.     trace_return();
  493. #endif
  494.     return(OK);
  495.    }
  496.  getyx(CURRENT_WINDOW,y,x);
  497.  if (CURRENT_VIEW->focus_line == 0
  498.  ||  CURRENT_VIEW->focus_line == CURRENT_FILE->number_lines+1)
  499.    {
  500. #ifdef TRACE
  501.     trace_return();
  502. #endif
  503.     return(OK);
  504.    }
  505. /*---------------------------------------------------------------------*/
  506. /* Find the current LINE pointer for the focus_line.                   */
  507. /*---------------------------------------------------------------------*/
  508.  curr = ll_find(CURRENT_FILE->first_line,CURRENT_VIEW->focus_line);
  509. /*---------------------------------------------------------------------*/
  510.  post_process_line(CURRENT_VIEW->focus_line);
  511. /*---------------------------------------------------------------------*/
  512. /* Validate that the supplied file is valid.                           */
  513. /*---------------------------------------------------------------------*/
  514.  strcpy(edit_fname,dir_path);
  515.  strcat(edit_fname,curr->line+file_start);
  516.  if (splitpath(edit_fname) == ERROR)
  517.    {
  518.     display_error(10,temp_cmd);
  519. #ifdef TRACE
  520.     trace_return();
  521. #endif
  522.     return(ERROR);
  523.    }
  524. /*---------------------------------------------------------------------*/
  525. /* Edit the file.                                                      */
  526. /*---------------------------------------------------------------------*/
  527.  strcpy(edit_fname,sp_path);
  528.  strcat(edit_fname,sp_fname);
  529.  rc = Edit(edit_fname);
  530. #ifdef TRACE
  531.  trace_return();
  532. #endif
  533.  return(rc);
  534. }
  535. /*man-start*********************************************************************
  536. COMMAND
  537.      sos_endchar - move cursor to end/start of focus line
  538.  
  539. SYNTAX
  540.      ** effective only if bound to a key **
  541.  
  542. DESCRIPTION
  543.      The sos_endchar command moves the cursor to the first character
  544.      displayed in the current window, if the cursor is after the last
  545.      character displayed in the current window, or to the position after
  546.      the last character displayed in the current window, if the cursor is
  547.      anywhere else.
  548.  
  549. COMPATIBILITY
  550.      The possible combinations of VERIFY etc. make mimicing *EDIT very
  551.      difficult. The command is, on the surface, compatible.
  552.  
  553. STATUS
  554.      incomplete-problem determining exactly where the cursor should go
  555.      when a verify end is in place and we are going to the end of line
  556. **man-end**********************************************************************/
  557. #ifdef PROTO
  558. int Sos_endchar(unsigned char *params)
  559. #else
  560. int Sos_endchar(params)
  561. unsigned char *params;
  562. #endif
  563. /***********************************************************************/
  564. {
  565. /*--------------------------- local data ------------------------------*/
  566.  register short i;
  567.  unsigned short col,x,y,line_col;
  568. /*--------------------------- processing ------------------------------*/
  569. #ifdef TRACE
  570.  trace_function("commsos.c: Sos_endchar");
  571. #endif
  572.  getyx(CURRENT_WINDOW,y,x);
  573.  switch(CURRENT_VIEW->current_window)
  574.    {
  575.     case WINDOW_PREFIX:
  576. #ifdef TRACE
  577.          trace_return();
  578. #endif
  579.          return(OK);
  580.          break;
  581.     case WINDOW_COMMAND:
  582.          if (x >= cmd_rec_len)
  583.             wmove(CURRENT_WINDOW,y,0);
  584.          else
  585.             wmove(CURRENT_WINDOW,y,cmd_rec_len);
  586. #ifdef TRACE
  587.          trace_return();
  588. #endif
  589.          return(OK);
  590.          break;
  591.     default:
  592.          break;
  593.    }
  594. /*---------------------------------------------------------------------*/
  595. /* Processing from here is for main window only.                       */
  596. /*---------------------------------------------------------------------*/
  597.  line_col = x + CURRENT_VIEW->verify_col;
  598.  if (line_col > min(rec_len,CURRENT_VIEW->verify_end))
  599.    {
  600.     CURRENT_VIEW->verify_col = max(CURRENT_VIEW->verify_start,1);
  601.     show_page();
  602.     wmove(CURRENT_WINDOW,y,0);
  603.    }
  604.  else
  605.    {
  606.     if (rec_len < CURRENT_SCREEN.cols)
  607.       {
  608.        x = min(rec_len-(CURRENT_VIEW->verify_col-1),CURRENT_VIEW->verify_end);
  609.        wmove(CURRENT_WINDOW,y,x);
  610.       }
  611.     else
  612.       {
  613.        x = CURRENT_SCREEN.cols / 2;
  614.        CURRENT_VIEW->verify_col = rec_len-x+1;
  615.        show_page();
  616.        wmove(CURRENT_WINDOW,y,x);
  617.       }
  618.    }
  619. #ifdef TRACE
  620.  trace_return();
  621. #endif
  622.  return(OK);
  623. }
  624. /*man-start*********************************************************************
  625. COMMAND
  626.      sos_tabf - move cursor to next tab stop
  627.  
  628. SYNTAX
  629.      ** effective only if bound to a key **
  630.  
  631. DESCRIPTION
  632.      The sos_tabf command causes the cursor to move to the next tab column
  633.      as set by the TABS command. (The default is 8).
  634.      If the resulting column is beyond the right hand edge of the main
  635.      window, the window will scroll half a window.
  636.  
  637. COMPATIBILITY
  638.      Does not line tab to next line if after the right hand tab column.
  639.  
  640. SEE ALSO
  641.      tabs
  642.  
  643. STATUS
  644.      Complete.
  645. **man-end**********************************************************************/
  646. #ifdef PROTO
  647. int Sos_tabf(unsigned char *params)
  648. #else
  649. int Sos_tabf(params)
  650. unsigned char *params;
  651. #endif
  652. /***********************************************************************/
  653. {
  654. extern char tabkey_insert,tabkey_overwrite;
  655. /*--------------------------- local data ------------------------------*/
  656.  unsigned short x,y,num_cols,next_tab_col;
  657. /*--------------------------- processing ------------------------------*/
  658. #ifdef TRACE
  659.  trace_function("commsos.c: Sos_tabf");
  660. #endif
  661. /*---------------------------------------------------------------------*/
  662. /* If the actual tab character is to be display then exit so that      */
  663. /* edit() can process it as a raw key.                                 */
  664. /*---------------------------------------------------------------------*/
  665.  if (mode_insert && tabkey_insert == 'C')
  666.    {
  667. #ifdef TRACE
  668.     trace_return();
  669. #endif
  670.     return(RAW_KEY);
  671.    }
  672.  if (!mode_insert && tabkey_overwrite == 'C')
  673.    {
  674. #ifdef TRACE
  675.     trace_return();
  676. #endif
  677.     return(RAW_KEY);
  678.    }
  679.  
  680.  getyx(CURRENT_WINDOW,y,x);
  681. /*---------------------------------------------------------------------*/
  682. /* First determine the number of characters to move to the right from  */
  683. /* the current column.                                                 */
  684. /*---------------------------------------------------------------------*/
  685.  num_cols = (CURRENT_VIEW->tabs) -
  686.             ((x + CURRENT_VIEW->verify_col) % CURRENT_VIEW->tabs);
  687.  next_tab_col = x + CURRENT_VIEW->verify_col + num_cols;
  688. /*---------------------------------------------------------------------*/
  689. /* Check for going past end of line - MAX_LINE_LENGTH                  */
  690. /*---------------------------------------------------------------------*/
  691.  if (CURRENT_VIEW->verify_col+x+num_cols > MAX_LINE_LENGTH)
  692.    {
  693. #ifdef TRACE
  694.     trace_return();
  695. #endif
  696.     return(OK);
  697.    }
  698. /*---------------------------------------------------------------------*/
  699. /* For all windows, if the new cursor position does not exceed the     */
  700. /* right edge, move there.                                             */
  701. /*---------------------------------------------------------------------*/
  702.  if (x+num_cols <= CURRENT_SCREEN.cols-1)
  703.    {
  704.     wmove(CURRENT_WINDOW,y,x+num_cols);
  705. #ifdef TRACE
  706.     trace_return();
  707. #endif
  708.     return(OK);
  709.    }
  710. /*---------------------------------------------------------------------*/
  711. /* For MAIN window, if the new cursor position exceeds the right edge  */
  712. /* scroll the window half the width of the main window.                */
  713. /*---------------------------------------------------------------------*/
  714.  if (CURRENT_VIEW->current_window == WINDOW_MAIN)
  715.     if (x+num_cols > CURRENT_SCREEN.cols-1)
  716.       {
  717.        x = CURRENT_SCREEN.cols / 2;
  718.        CURRENT_VIEW->verify_col += x;
  719.        show_page();
  720.        wmove(CURRENT_WINDOW,y,(next_tab_col-CURRENT_VIEW->verify_col));
  721. /*       wmove(CURRENT_WINDOW,y,(x+num_cols)-1);*/
  722.       }
  723. #ifdef TRACE
  724.  trace_return();
  725. #endif
  726.  return(OK);
  727. }
  728. /*man-start*********************************************************************
  729. COMMAND
  730.      sos_tabwordb - move cursor to beginning of previous word
  731.  
  732. SYNTAX
  733.      ** effective only if bound to a key **
  734.  
  735. DESCRIPTION
  736.      The sos_tabwordb command causes the cursor to move to the first character
  737.      of the word to the left or to the start of the line if no more
  738.      words precede.
  739.      If the resulting column is beyond the left hand edge of the main
  740.      window, the window will scroll half a window.
  741.  
  742. COMPATIBILITY
  743.      Compatible.
  744.  
  745. SEE ALSO
  746.      sos_tabwordf
  747.  
  748. STATUS
  749.      Complete.
  750. **man-end**********************************************************************/
  751. #ifdef PROTO
  752. int Sos_tabwordb(unsigned char *params)
  753. #else
  754. int Sos_tabwordb(params)
  755. unsigned char *params;
  756. #endif
  757. /***********************************************************************/
  758. {
  759. /*--------------------------- local data ------------------------------*/
  760.  unsigned short x,y,temp_rec_len;
  761.  short start_word_col;
  762.  unsigned short word_break;
  763.  unsigned char *temp_rec;
  764.  register short i;
  765.  short num_cols,col_pos,col,rec_pos,left_col;
  766. /*--------------------------- processing ------------------------------*/
  767. #ifdef TRACE
  768.  trace_function("commsos.c: Sos_tabwordb");
  769. #endif
  770. /*---------------------------------------------------------------------*/
  771. /* This function is not applicable to the PREFIX window.               */
  772. /*---------------------------------------------------------------------*/
  773.  getyx(CURRENT_WINDOW,y,x);
  774.  switch(CURRENT_VIEW->current_window)
  775.    {
  776.     case WINDOW_PREFIX:
  777.          display_error(38,"");
  778. #ifdef TRACE
  779.          trace_return();
  780. #endif
  781.          return(OK);
  782.          break;
  783.     case WINDOW_MAIN:
  784.          temp_rec = rec;
  785.          temp_rec_len = rec_len;
  786.          left_col = CURRENT_VIEW->verify_col-1;
  787.          break;
  788.     case WINDOW_COMMAND:
  789.          temp_rec = cmd_rec;
  790.          temp_rec_len = cmd_rec_len;
  791.          left_col = 0;
  792.          break;
  793.    }
  794. /*---------------------------------------------------------------------*/
  795. /* Determine the start of the prior word, or go to the start of the    */
  796. /* line if already at or before beginning of prior word.               */
  797. /*---------------------------------------------------------------------*/
  798.  word_break = 0;
  799.  start_word_col = (-1);
  800.  for (i=left_col+x;i>0;i--)
  801.    {
  802.     switch(word_break)
  803.       {
  804.        case 0:  /* still in current word */
  805.             if (*(temp_rec+i) == ' ')
  806.                word_break++;
  807.             break;
  808.        case 1:  /* in first blank space */
  809.             if (*(temp_rec+i) != ' ')
  810.                word_break++;
  811.             break;
  812.        case 2:  /* in previous word */
  813.             if (*(temp_rec+i) == ' ')
  814.               {
  815.                start_word_col = i+1;
  816.                word_break++;
  817.               }
  818.             break;
  819.        default: /* should not get here */
  820.             break;
  821.       }
  822.     if (word_break == 3)
  823.        break;
  824.    }
  825.  if (start_word_col == (-1))
  826.     start_word_col = 0;
  827.  num_cols = (x + left_col) - start_word_col;
  828. /*---------------------------------------------------------------------*/
  829. /* For all windows, if the new cursor position is not less than the    */
  830. /* left edge,  move there.                                             */
  831. /* If in command window, this should always be true.                   */
  832. /*---------------------------------------------------------------------*/
  833.  col_pos = x;
  834.  if (col_pos-num_cols >= 0)
  835.    {
  836.     wmove(CURRENT_WINDOW,y,x-num_cols);
  837. #ifdef TRACE
  838.     trace_return();
  839. #endif
  840.     return(OK);
  841.    }
  842. /*---------------------------------------------------------------------*/
  843. /* For MAIN window, if the new cursor position exceeds the right edge  */
  844. /* scroll the window half the width of the main window.                */
  845. /*---------------------------------------------------------------------*/
  846.  rec_pos = CURRENT_VIEW->verify_col + x - num_cols + 1;
  847.  
  848.  x = CURRENT_SCREEN.cols / 2;
  849.  col = max((short)CURRENT_VIEW->verify_start,
  850.                  (short)(CURRENT_VIEW->verify_col-1) - (short)x);
  851.  CURRENT_VIEW->verify_col = col;
  852.  show_page();
  853.  wmove(CURRENT_WINDOW,y,rec_pos-CURRENT_VIEW->verify_col-1);
  854. #ifdef TRACE
  855.  trace_return();
  856. #endif
  857.  return(OK);
  858. }
  859. /*man-start*********************************************************************
  860. COMMAND
  861.      sos_tabwordf - move cursor to start of next word
  862.  
  863. SYNTAX
  864.      ** effective only if bound to a key **
  865.  
  866. DESCRIPTION
  867.      The sos_tabwordf command causes the cursor to move to the first character
  868.      of the next word to the right or to the end of the line if no more
  869.      words follow.
  870.      If the resulting column is beyond the right hand edge of the main
  871.      window, the window will scroll half a window.
  872.  
  873. COMPATIBILITY
  874.      Compatible.
  875.  
  876. SEE ALSO
  877.      sos_tabwordb
  878.  
  879. STATUS
  880.      Complete.
  881. **man-end**********************************************************************/
  882. #ifdef PROTO
  883. int Sos_tabwordf(unsigned char *params)
  884. #else
  885. int Sos_tabwordf(params)
  886. unsigned char *params;
  887. #endif
  888. /***********************************************************************/
  889. {
  890. /*--------------------------- local data ------------------------------*/
  891.  unsigned short x,y,temp_rec_len,num_cols;
  892.  short start_word_col,left_col;
  893.  bool word_break;
  894.  unsigned char *temp_rec;
  895.  register short i;
  896. /*--------------------------- processing ------------------------------*/
  897. #ifdef TRACE
  898.  trace_function("commsos.c: Sos_tabwordf");
  899. #endif
  900. /*---------------------------------------------------------------------*/
  901. /* This function is not applicable to the PREFIX window.               */
  902. /*---------------------------------------------------------------------*/
  903.  getyx(CURRENT_WINDOW,y,x);
  904.  switch(CURRENT_VIEW->current_window)
  905.    {
  906.     case WINDOW_PREFIX:
  907.          display_error(38,"");
  908. #ifdef TRACE
  909.          trace_return();
  910. #endif
  911.          return(OK);
  912.          break;
  913.     case WINDOW_MAIN:
  914.          temp_rec = rec;
  915.          temp_rec_len = rec_len;
  916.          left_col = CURRENT_VIEW->verify_col-1;
  917.          break;
  918.     case WINDOW_COMMAND:
  919.          temp_rec = cmd_rec;
  920.          temp_rec_len = cmd_rec_len;
  921.          left_col = 0;
  922.          break;
  923.    }
  924. /*---------------------------------------------------------------------*/
  925. /* If we are after the last column of the line, then just ignore the   */
  926. /* command and leave the cursor where it is.                           */
  927. /*---------------------------------------------------------------------*/
  928.  if ((x + left_col) > temp_rec_len)
  929.    {
  930. #ifdef TRACE
  931.     trace_return();
  932. #endif
  933.     return(OK);
  934.    }
  935. /*---------------------------------------------------------------------*/
  936. /* Determine the start of the next word, or go to the end of the line  */
  937. /* if already at or past beginning of last word.                       */
  938. /*---------------------------------------------------------------------*/
  939.  word_break = FALSE;
  940.  start_word_col = (-1);
  941.  for (i=left_col+x;i<temp_rec_len;i++)
  942.    {
  943.     if (*(temp_rec+i) == ' ')
  944.        word_break = TRUE;
  945.     else
  946.       {
  947.        if (word_break)
  948.          {
  949.           start_word_col = i;
  950.           break;
  951.          }
  952.       }
  953.    }
  954.  if (start_word_col == (-1))
  955.     start_word_col = temp_rec_len;
  956.  num_cols =  start_word_col - (x + CURRENT_VIEW->verify_col -1);
  957. /*---------------------------------------------------------------------*/
  958. /* For all windows, if the new cursor position does not exceed the     */
  959. /* right edge, move there.                                             */
  960. /* If in command window, this should always be true.                   */
  961. /*---------------------------------------------------------------------*/
  962.  if (x+num_cols <= CURRENT_SCREEN.cols-1
  963.  || CURRENT_VIEW->current_window == WINDOW_COMMAND)
  964.    {
  965.     wmove(CURRENT_WINDOW,y,x+num_cols);
  966. #ifdef TRACE
  967.     trace_return();
  968. #endif
  969.     return(OK);
  970.    }
  971. /*---------------------------------------------------------------------*/
  972. /* For MAIN window, if the new cursor position exceeds the right edge  */
  973. /* scroll the window half the width of the main window.                */
  974. /*---------------------------------------------------------------------*/
  975.  if (x+num_cols > CURRENT_SCREEN.cols-1)
  976.    {
  977.     x = CURRENT_SCREEN.cols / 2;
  978.     CURRENT_VIEW->verify_col += x;
  979.     show_page();
  980.     wmove(CURRENT_WINDOW,y,(start_word_col-CURRENT_VIEW->verify_col+1));
  981.    }
  982. #ifdef TRACE
  983.  trace_return();
  984. #endif
  985.  return(OK);
  986. }
  987. /*man-start*********************************************************************
  988. COMMAND
  989.      sos_undo - undo changes to the current line
  990.  
  991. SYNTAX
  992.      ** effective only if bound to a key **
  993.  
  994. DESCRIPTION
  995.      The sos_undo command causes the contents of the focus line (or the
  996.      command line) to be reset to the contents before the cursor was
  997.      positioned there.
  998.  
  999. COMPATIBILITY
  1000.      Basically compatible. Doesn't restore the cursor to the original
  1001.      column position.
  1002.  
  1003. STATUS
  1004.      Complete.
  1005. **man-end**********************************************************************/
  1006. #ifdef PROTO
  1007. int Sos_undo(unsigned char *params)
  1008. #else
  1009. int Sos_undo(params)
  1010. unsigned char *params;
  1011. #endif
  1012. /***********************************************************************/
  1013. {
  1014. /*--------------------------- local data ------------------------------*/
  1015.  unsigned short x,y,temp_rec_len,num_cols;
  1016.  short start_word_col;
  1017.  bool word_break;
  1018.  unsigned char *temp_rec;
  1019.  register short i;
  1020. /*--------------------------- processing ------------------------------*/
  1021. #ifdef TRACE
  1022.  trace_function("commsos.c: Sos_undo");
  1023. #endif
  1024.  if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
  1025.    {
  1026.     display_error(38,"...at the moment.");
  1027. #ifdef TRACE
  1028.     trace_return();
  1029. #endif
  1030.     return(OK);
  1031.    }
  1032.  if (CURRENT_VIEW->current_window == WINDOW_MAIN)
  1033.     pre_process_line(CURRENT_VIEW->focus_line);
  1034.  else
  1035.    {
  1036.     wmove(CURRENT_WINDOW_COMMAND,0,0);
  1037.     wclrtoeol(CURRENT_WINDOW_COMMAND);
  1038.    }
  1039.   show_page();
  1040. #ifdef TRACE
  1041.  trace_return();
  1042. #endif
  1043.  return(OK);
  1044. }
  1045.